$(document).ready(function () {
    $.init();
    var recordNum1 = 0;
    var recordNum2 = 0;
    var mySwiper = new Swiper ('.swiper-container', {
        direction: 'horizontal',
        autoplay : 3000,
        loop: true,

        pagination: '.swiper-pagination',
    })
    $('.bottom_popup').click(function () {
        // $('.user_bottom_1').hide();
        // $('.user_bottom_2').show();
        $.popup('.popup-about')
    })

    var changeNum = 0;
    var releaseNum = 0;
    var compareNum = 0;
    var loop = 0;

    $('.knob_input').change(function(){
        var input_val = Math.abs(parseInt($('.knob_input').val()));
        $('.knob_input').val(input_val);
        var mod_val = input_val%500;
        loop = parseInt(input_val/500);
        changeNum = mod_val + (loop*500);
         $('.knob').val(mod_val).trigger('change'); 
    })

    $(".knob").knob({
        max: 500,
        min: 1,
        thickness: .1,
        fgColor: '#157FC7',
        bgColor: '#BBB',
        angleOffset:"0" ,
        'change':function (e) {
            console.log('change.loop = '+loop)
            changeNum = e + (loop*500);

            if ((compareNum -changeNum) >400) {
                loop++;
                console.log('pass.loop'+loop);
                changeNum = e + (loop*500);
                console.log("changeNum"+changeNum+'||compareNum='+compareNum)
            }else if((changeNum - compareNum) >400){          
                loop--;
                console.log('back.loop'+loop);
                changeNum = e + (loop*500);
                console.log("changeNum"+changeNum+'||compareNum='+compareNum)
            }
            
            compareNum = changeNum; 
            releaseNum = e + (loop*500);
            if (releaseNum < 0) {
                //正位
                loop = 0;
                // changeNum = e + (loop*500);
                // compareNum = changeNum;
                releaseNum = 1;
                $('.knob').val(1).trigger('change'); 
            }
            console.log(releaseNum);
            $('.knob_input').val(parseInt(releaseNum));

        },
        'release':function(e){
            releaseNum = e + (loop*500);
            if (releaseNum < 0) {
                //正位
                loop = 0;
                // changeNum = e + (loop*500);
                // compareNum = changeNum;
                releaseNum = 1;
                $('.knob').val(1).trigger('change'); 
            }
            console.log(releaseNum);
            $('.knob_input').val(releaseNum);
            
        },
        "draw" : function () {
            // "tron" case

            if(this.$.data('skin') == 'tron') {

                this.cursorExt = 0.08;



                var a = this.arc(this.cv)  // Arc

                    , pa                   // Previous arc

                    , r = 1;

                this.g.lineWidth = this.lineWidth;

                if (this.o.displayPrevious) {

                    pa = this.arc(this.v);

                    this.g.beginPath();

                    this.g.strokeStyle = this.pColor;

                    this.g.arc(this.xy, this.xy, this.radius - this.lineWidth, pa.s, pa.e, pa.d);

                    this.g.stroke();

                }



                this.g.beginPath();

                this.g.strokeStyle = r ? this.o.fgColor : this.bgColor ;
                // this.g.strokeStyle = r ? this.o.bgColor : this.bgColor ;

                this.g.arc(this.xy, this.xy, this.radius - this.lineWidth, a.s, a.e, a.d);

                this.g.stroke();



                this.g.lineWidth = 5;

                this.g.beginPath();

                // this.g.strokeStyle = this.o.fgColor;
                this.g.strokeStyle = this.o.bgColor;

                this.g.arc( this.xy, this.xy, this.radius - this.lineWidth - 20 + this.lineWidth * 2 / 3, 0, 2 * Math.PI, false);

                this.g.stroke();



                return false;

            }

        }
    });
    $("input.infinite").knob(

        {

            min : 0

            , max : 20

            , stopper : false

            , change : function () {

            if(v > this.cv){

                if(up){

                    decr();

                    up=0;

                }else{up=1;down=0;}

            } else {

                if(v < this.cv){

                    if(down){

                        incr();

                        down=0;

                    }else{down=1;up=0;}

                }

            }

            v = this.cv;

        }

        });


})